package com.tang.algorithm.binaryserch;

/**
 * @author tlm
 * @Description
 * @date 2020/7/10 5:53 下午
 */
public class LeetCode35 {
	public static void main(String[] args) {
		int[] a = { 1, 3, 5, 6 };
		System.out.println(searchInsert(a, 0));
	}

	public static int searchInsert(int[] nums, int target) {
		int left = 0, right = nums.length - 1;
		while (left <= right) {
			int mid = (left + right) >>> 1;
			if (nums[mid] == target) {
				return mid;
			} else if (nums[mid] < target) {
				left = mid + 1;
			} else if (nums[mid] > target) {
				right = mid - 1;
			}
		}

		return left;
	}

}
